package dfferber.xstream;

import java.util.HashSet;
import java.util.Set;

import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.converters.reflection.ReflectionProvider;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import com.thoughtworks.xstream.mapper.Mapper;

public class PojoConverter extends AbstractPojoConverter {

	private Set<Class<?>> pojoClasses = new HashSet<Class<?>>();
	private HashSet<Package> pojoPackages = new HashSet<Package>();
	
	public PojoConverter(Mapper mapper, PojoReflectionProvider pojoReflectionProvider, ReflectionProvider reflectionProvider) {
		super(mapper, pojoReflectionProvider, reflectionProvider);
	}

	@Override
	public boolean canConvert(Class type) {
		return pojoPackages.contains(type.getPackage()) || pojoClasses.contains(type);
	}
	
	public void registerPojoClass(Class<?> type) {
		pojoClasses.add(type);
	}
	
	public void registerPojoPackage(Package thePackage) {
		pojoPackages.add(thePackage);
	}
	
	@Override
	public void marshal(Object original, HierarchicalStreamWriter writer, MarshallingContext context) {
		super.marshal(original, writer, context);
	}
	
	@Override
	public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
		return super.unmarshal(reader, context);
	}
	
}
